/**
 * Created by Administrator on 2017/10/5 0005.
 */
(function ($j) {
    function init() {
        renderData();
        bindBtnEvent();
    }

    function renderData() {

        var tab = $j.GetQueryString('tab');
        if(tab != null) {
            $('.buttons-tab a').removeClass('active');
            $('.' + tab).addClass('active');
        }
        var _val = $('#search').val();
        var param = {
            name: _val,
            phone: _val
        }
        $.showPreloader();
        $j.restPost('/referrer/doQuery', param).done(function (mess, data) {
            var unInstall = '';
            var install = '';
            $(data.list).each(function (i, item) {
                if (item.status == '未安装') {
                    unInstall += '<tr><td>' + item.name + '</td><td>' + item.phone + '</td><td>' + item.status + '</td><td>0</td></tr>';
                } else if (item.status == '已安装') {
                    install += '<tr><td>' + item.name + '</td><td>' + item.phone + '</td><td>' + item.status + '</td><td>100</td></tr>';
                }
            });
            $('#unInstall').html(unInstall);
            $('#install').html(install);
            $.hidePreloader();
        }).fail(function (mess) {
            $.toast(mess);
            $.hidePreloader();
        });
    }


    function bindBtnEvent() {
        //输入框事件
        $('.doSearch').off('click').on('click', function () {
            $.showPreloader();
            renderData();
        });
    }

    init();
})(jQuery);